package org.his.controller.basicdata.huiyuan;

import org.his.dao.CardTranInfoDao;
import org.his.pojo.huiyuan.CardTranInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@RequestMapping("/cardtraninfo")
@Controller
public class CardTranInfoController {

    @Autowired
    private CardTranInfoDao cardTranInfoDao;
    @RequestMapping("/get")
    @ResponseBody
    public CardTranInfo get(Integer cardMemberId) throws Exception{
        return cardTranInfoDao.getByCardMemberId(cardMemberId);
    }

    @PostMapping("/edit")
    @ResponseBody
    public Map<String ,Object> edit(Integer cardMemberId,Integer currentBalance ,Integer chongzhi) throws Exception{
        Map<String,Object> map = new HashMap<>();
        CardTranInfo cardTranInfo = new CardTranInfo();
        cardTranInfo.setCardMemberId(cardMemberId);
        cardTranInfo.setCurrentBalance(currentBalance);
        cardTranInfo.setCurrentBalance(cardTranInfo.getCurrentBalance() + chongzhi);

        cardTranInfoDao.update(cardTranInfo);

        return map;
    }

    @PostMapping("/shoufei")
    @ResponseBody
    public Map<String ,Object> shoufei(Integer cardTranId,Integer chongzhi) throws Exception{
        Map<String,Object> map = new HashMap<>();
        CardTranInfo cardTranInfo = new CardTranInfo();

        cardTranInfo.setCardMemberId(cardTranId);
        cardTranInfo.setCurrentBalance(chongzhi);

        cardTranInfoDao.update(cardTranInfo);
        return map;
    }
}
